﻿@model DeliveryManage.Model.SM_SysConfig
@{
    Layout = null;
    DeliveryManage.Models.ReturnMsgModel returnMsg = ViewBag.ReturnMsgModel;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>系统配置管理</title>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />

    <link rel="stylesheet" href="~/Content/font.css" />
    <link rel="stylesheet" href="~/Content/framemain.css" />
    <link rel="stylesheet" href="~/Content/icon/iconfont.css" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <script type="text/javascript" src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="~/Content/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="~/Scripts/framemain.js"></script>
    <script type="text/javascript" src="~/Scripts/laymain.js"></script>
    <script type="text/javascript" src="~/Scripts/common.js"></script>
    <script type="text/javascript" src="~/Scripts/Validform_v5.3.2_min.js"></script>
    <link rel="stylesheet" href="~/Content/pagination.css" />
    <script type="text/javascript" src="~/Scripts/framemain.js"></script>
    <script type="text/javascript" src="~/Scripts/laymain.js"></script>
    <style>
        .layui-tab {
            background: white;
        }

        .layui-form-item {
            padding: 10px !important;
        }
        .layui-tab-title {
            margin: -10px 10px 0px 10px;
            padding-top: 10px;
        }
        .layui-tab-content {
            padding-top: 0px;
        }
        .input {
            width: 180px !important;
        }
        .layui-upload-drag {
            padding:5px;
        }
        dl dt {
            width: 190px !important;
        }
        dl dd {
            margin-left:200px !important;
        }
        th {
            width: 65px;
            text-align: center;
            background-color: #f2f2f2;
        }
    </style>
    <script>
        //注意：选项卡 依赖 element 模块，否则无法进行功能性操作
        layui.use('element', function () {
            var element = layui.element;
        });

        $(document).ready(function () {
            $("#myform").submit(function () {
                data= $(this).serialize(),
                tishi = '修改配置，您确定吗？'
                layer.confirm(tishi, { icon: 3, title: '提示' }, function (index) {
                $.ajax({
                    type: "POST",
                    url: "/System/SystemConfigEdit",
                    data: data,
                    success: function (obj) {
                        if (obj.code == 200) {
                            layer.alert(obj.msg, { icon: 6 }, function () {
                                layer.close();
                                window.location.href = '/System/SystemConfig?layid=' + $('#layid').val();
                            });
                        } else {
                            layer.alert(obj.msg, { icon: 5 }, function () {
                                layer.close();
                            });
                        }
                    }
                })
                layer.close(index);
                })
                return false;
            })
        })

    $(function () {
            //操作提示
            if (@returnMsg.code == 400) {
                layer.msg('@returnMsg.msg', { icon: 5, title: '提示' }, function (index) {
                  layer.close(index);
                })
            }
        })
    </script>
</head>
<body>
    <form id="myform">
        <div class="x-nav ">
            <span class="layui-breadcrumb">
                <a href="javascript:;">首页</a>
                <a><cite>系统配置</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>

        @{
            if (returnMsg.code == 200)
            {
                <div class="layui-fluid">
                    <div class="layui-tab" lay-filter="tabtest">
                        <ul class="layui-tab-title">
                            <li lay-id="1" style="display:none">邮件设置</li>
                            <li lay-id="5">文件上传设置</li>
                        </ul>
                        <input type="hidden" id="layid" value="@ViewBag.layid" />
                        <div class="layui-tab-content ">
                            <!--邮箱设置-->
                            <div class="layui-tab-item">
                                <div class="tab-content">
                                    <div class="iconfont left-nav-li"></div>
                                    <dl>
                                        <dt>服务器地址</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.email_host, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*邮件服务器地址</span>
                                        </dd>
                                    </dl>
                                    <dl>
                                        <dt>端口</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.email_port, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*默认25和80，SSL方式采用465</span>
                                        </dd>
                                    </dl>
                                    <dl>
                                        <dt>发件人昵称</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.email_send_username, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*发件人昵称</span>
                                        </dd>
                                    </dl>
                                    <dl>
                                        <dt>发件人地址</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.email_send_adress, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*发件人邮件地址</span>
                                        </dd>
                                    </dl>
                                    <dl>
                                        <dt>发件人授权账号</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.email_send_user, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*发件人登录授权账号</span>
                                        </dd>
                                    </dl>
                                    <dl>
                                        <dt>发件人授权账号密码</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.email_send_pwd, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*发件人登录授权账号密码</span>
                                        </dd>
                                    </dl>
                                    <dl>
                                        <dt>是否启用SSL</dt>
                                        <dd class="layui-form">
                                            <input type="radio" name="email_enable_ssl" value="true" @(Model.email_enable_ssl == true ? "checked=\"checked\"" : "") />启用
                                            <input type="radio" name="email_enable_ssl" value="false" @(Model.email_enable_ssl == false ? "checked=\"checked\"" : "") />关闭
                                            <span class="Validform_checktip">*启用时，端口请使用465</span>
                                        </dd>
                                    </dl>
                                </div>
                            </div>
                            <!--文件上传设置-->
                            <div class="layui-tab-item">
                                <div class="tab-content">
                                    <div class="iconfont left-nav-li"></div>
                                    <dl>
                                        <dt>文件上传地址</dt>
                                        <dd class="layui-form">
                                            @Html.TextBoxFor(m => m.file_server_url, new { @class = "input small", @sucmsg = " " })
                                            <span class="Validform_checktip">*蒋文件上传到设置的文件服务器地址，默认本地服务器</span>
                                        </dd>
                                    </dl>
                                </div>
                            </div>
                        </div>

                        <!--工具栏-->
                        <div class="layui-form-item">
                            <input id="btnSubmit" name="btnSubmit" type="submit" value="保存信息" class="layui-btn" />
                        </div>
                    </div>
                </div>
            }
        }
    </form>
    <script>
            layui.use(['form', 'layer', 'upload', 'element'],
                function () {
                    $ = layui.jquery;
                    var form = layui.form,
                        layer = layui.layer,
                        upload = layui.upload,
                        element = layui.element;

                    //默认选中
                    var layid = $('#layid').val();
                    //获取hash来切换选项卡，假设当前地址的hash为lay-id对应的值
                    //var layid = location.hash.replace(/^#tabtest=/, $('#layid').val());
                    element.tabChange('tabtest', layid); 

                    //监听Tab切换，以改变地址hash值
                    element.on('tab(tabtest)', function () {
                        location.hash = 'tabtest=' + this.getAttribute('lay-id');
                        $('#layid').val(this.getAttribute('lay-id'));
                        //console.log('当前激活的选项卡下标：' + this.getAttribute('lay-id'));
                    });

                        //拖拽上传
                    upload.render({
                        elem: '#uploadButton',
                        exts: 'apk', //只允许上传apk后缀文件
                        method: 'post', //默认post
                        url: '/System/ApkFileUpload',  //此处配置你自己的上传接口即可
                        data: { 'versions': getDynamicData },
                        accept: 'file',
                        before: function () {
                            i = showLoad();
                        },
                        done: function (obj) {
                            if (obj.status == true) {
                                $("#app_apk_file_path").val(obj.data);
                                $("#apk_file_path").text(obj.data);
                                layer.msg(obj.msg, { icon: 6, title: '提示' }, function (index) {
                                    layui.$('#uploadDemoView').removeClass('layui-hide').find('a').attr('src', "../images/mp3.jpg");

                                    closeLoad(i);
                                });
                            } else {
                                layer.confirm(obj.msg, { icon: 5, title: '提示' }, function (index) {
                                    layer.close();
                                    location.reload();
                                });
                            }
                        }
                      });
                }
            );
        // 动态数据函数
        function getDynamicData() {
            var apkversions = $('#app_apk_versions').val();
            return apkversions; // 这里可以根据实际需求来返回动态数据
        }
        function showLoad() {
            return layer.msg('上传中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: 'auto', time: 100000 });
        }

        function closeLoad(index) {
            layer.close(index);
        }
    </script>
</body>
</html>